#ifndef COLLEAGUE_H__
#define COLLEAGUE_H__

//include header
#include <covariant>
#include <string>
#include "Mediator.h"

//using namespace
using namespace std;


namespace npMediator
{
    //class forward declaration
    
    class Colleague ://  public BaseClass
        public covariant
    {
        //friend
        
        //embedded type
        public: enum class ErrorEnum
            {
                NullMediator = 1
            };
        
        //class skeleton
        public: Colleague();
        public: Colleague(const Colleague& cpy);
        public: Colleague(Colleague&& mov) noexcept;
        public: virtual ~Colleague();
        public: Colleague& operator=(const Colleague& asn);
        public: Colleague& operator=(Colleague&& mva) noexcept;
        public: virtual shared_ptr<covariant> clone() const throw();
        public: virtual shared_ptr<covariant> steal(void* sft=nullptr) throw();

        //other constructors
        public: Colleague(int id, weak_ptr<Mediator> mediator);
        
        //public methods
        public: virtual void send(const string& msg, int targetId) throw(ErrorEnum) = 0;
        public: virtual void notify(const string& msg) throw() = 0;

        public: int getId() const throw();
        
        //protected methods
        protected: weak_ptr<Mediator> getMediator() const throw();
        
        //private methods
        
        //protected data
        /* 类中不应该存在protected 访问级别的data
         * 要么私有，要么私有而后给出protected 访问级别的methods !!! */
        
        //private data
        /* 类中不应存在指针类型成员，
         * 取而代之，应使用智能指针予以包裹
         * 使用shared_ptr表示类拥有指针指向对象
         * 使用weak_ptr表示类仅可以使用指针指向对象
         * 智能指针对指针成员的封装和使用准则：
         * 1.类对象不允许使用unique_ptr包裹
         * 2.推敲业务逻辑，如果是共享的(share_ptr)，则尽可能少的共享指针对象
         * 3.如果从业务逻辑中发现类仅仅使用某个指针所指对象，则务必使用weak_ptr包裹指针，
         *   以此切实地描述这种使用而不拥有的关系
         * 4.类成员weak_ptr<*> ths，由其产生的，包裹this指针的，shared_ptr只允许在局部使用 */
        private: int id;
        private: weak_ptr<Mediator> mediator;
        //static part
        
        //others
    };

    //inline functions
    inline Colleague::Colleague() // : BaseClass()
    {
        this->id = 0;
        this->mediator = weak_ptr<Mediator>();
    }
    
    inline Colleague::Colleague(const Colleague& cpy) // : BaseClass(cpy)
    {
        this->id = cpy.id;
        this->mediator = cpy.mediator;
    }
    
    inline Colleague::Colleague(Colleague&& mov) noexcept // : BaseClass(move(mov))
    {
        this->id = mov.id;
        this->mediator = move(mov.mediator);
    }
    
    inline Colleague::~Colleague()
    {
        
    }
    
    inline Colleague& Colleague::operator=(const Colleague& asn)
    {
        if (this == &asn)
        {
            return *this;
        }
        else
        {
            // BaseClass::operator=(asn);
            
            //To do
            this->id = asn.id;
            this->mediator = asn.mediator;
            
            return *this;
        }
    }
    
    inline Colleague& Colleague::operator=(Colleague&& mva) noexcept
    {
        if (this == &mva)
        {
            return *this;
        }
        else
        {
            // BaseClass::operator=(move(mva));
            
            //To do
            this->id = mva.id;
            this->mediator = move(mva.mediator);
            
            return *this;
        }
    }
    
    inline shared_ptr<covariant> Colleague::clone() const throw()
    {
        //new an instance if not abstract.
        return shared_ptr<covariant>(); //shared_ptr<Colleague>(new Colleague(*this));
    }
    
    inline shared_ptr<covariant> Colleague::steal(void* sft) throw()
    {
        Colleague* shf = static_cast<Colleague*>(sft);
        if (this == shf)
        {
            return shared_ptr<covariant>();
        }
        else
        {
            shared_ptr<Colleague> ret;
            if (!shf)
            {
                //new an instance if not abstract.
                // ret = shared_ptr<Colleague>(new Colleague(*this));
                // shf = ret.get();
            }
            
            // BaseClass::steal(shf);
            
            //To do
            shf->id = this->id;
            shf->mediator = move(this->mediator);
            
            return ret;
        }
    }
    
    inline weak_ptr<Mediator> Colleague::getMediator() const throw()
    {
        return this->mediator;
    }

    inline int Colleague::getId() const throw()
    {
        return this->id;
    }
} // namespace npMediator


#endif //COLLEAGUE_H__
